class OsnNotify {
    func addNotifyMessage(_ osnId:String, _ timestamp:Int64, _ hash:String, _ content:Any) ->DMCCMessage {
        let m = gosnMessage.getMessageFromHash(hash)
        
        var mm =  DMCCMessage()
        if(m == nil){
            mm.target = osnId
            mm.direction = OsnMessageDirection.Receive
            mm.status = OsnMessageStatus.Readed
            mm.timestamp = timestamp
            mm.msgHash = hash
            mm.msgType = (content as? OsnMessageContent ?? OsnMessageContent()).contentType
            mm.content = content as! OsnMessageContent
            _ = gosnMessage.setMessage(mm)
        }else{
            mm = m!
        }
        return mm
    }
    func createGroupNotify(_ info:GroupUpdateInfo) ->OsnNotifyCreateGroup {
        let n = OsnNotifyCreateGroup()
        n.groupId = info.groupID
        n.groupName = info.name
        n.creator = info.owner
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
    func delMemberNotify(_ info:GroupUpdateInfo) ->OsnNotifyDelMember {
        let n = OsnNotifyDelMember()
        n.groupId = info.groupID
        n.operateUser = info.approver;
        n.kickedMembers = info.userList;
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
    func addMemberNotify(_ info:GroupUpdateInfo) ->OsnNotifyAddMember {
        let n = OsnNotifyAddMember()
        n.groupId = info.groupID
        n.invitees = info.userList
        n.invitor = info.invitor
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
    func quitGroupNotify(_ info:GroupUpdateInfo) ->OsnNotifyQuitGroup {
        let n = OsnNotifyQuitGroup()
        n.groupId = info.groupID
        n.quitMember = info.userList[0]
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
    func deleteGroupNotify(_ info:GroupUpdateInfo) ->OsnNotifyDeleteGroup {
        let n = OsnNotifyDeleteGroup()
        n.groupId = info.groupID
        n.operateUser = info.groupID
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
    func groupNotify(_ info:GroupUpdateInfo) ->OsnNotifyGroup {
        let n = OsnNotifyGroup()
        n.groupId = info.groupID
        n.info = info.text
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
    func addAdminrNotify(_ info:GroupUpdateInfo) ->OsnNotifyAddAdmin {
        let n = OsnNotifyAddAdmin()
        n.groupId = info.groupID
        n.adminMembers = info.userList
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
    func delAdminrNotify(_ info:GroupUpdateInfo) ->OsnNotifyDelAdmin {
        let n = OsnNotifyDelAdmin()
        n.groupId = info.groupID
        n.delMembers = info.userList
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
    func updateGroupNameNotify(_ info:GroupUpdateInfo) ->OsnNotifyUpdateGroupName {
        let n = OsnNotifyUpdateGroupName()
        n.groupId = info.groupID
        n.groupName = info.name
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
    
    func muteMemberNotify(_ info:GroupUpdateInfo) ->OsnNotifyNotifyMute {
        let n = OsnNotifyNotifyMute()
        n.groupId = info.groupID
        n.userList = info.userList
        n.range = info.muteRange
        n.info = info.state
        let m = addNotifyMessage(info.groupID, Int64(info.noticeServerTime) ?? OsnUtils.getTimeStamp(), info.msgHash, n)
        gosnConversation.updateConversationTimestamp(info.groupID, m.timestamp)
        return n
    }
}
let gosnNotify = OsnNotify()
